package com.jt.assistant.viewmodel

import androidx.lifecycle.MutableLiveData
import com.jt.assistant.base.BaseResult
import com.jt.assistant.bean.*
import com.jt.assistant.repository.LoginRepository
import com.yzp.mvvmlibrary.base.BaseViewModel

class LoginViewModel : BaseViewModel() {

    private val loginRepository by lazy {
        LoginRepository.getInstance()
    }



    val mLogin = MutableLiveData<BaseResult<LoginDataBean>>()
    fun login(userName: String, password: String): MutableLiveData<BaseResult<LoginDataBean>> {
        val params = Param::class.java.newInstance()
        params.userName = userName
        params.password = password
        launchGo({
            mLogin.value = loginRepository.login(params)
            if (!mLogin.value!!.isSuccess()) {
                defUI.toastEvent.postValue(mLogin.value!!.errorMsg)
            }
        }, true)
        return mLogin
    }

    val mGetUpgradeUlrValue = MutableLiveData<BaseResult<UpdateBean>>()
    fun getUpgradeUlr(
    ): MutableLiveData<BaseResult<UpdateBean>> {
        launchGo({
            mGetUpgradeUlrValue.value =
                loginRepository.getUpgradeUlr()
        }, true)
        return mGetUpgradeUlrValue
    }

    val mGetUpgradeValue = MutableLiveData<BaseResult<UpdateAppBean>>()
    fun getUpgrade(
        url:String,
        appInfo: AppInfo
    ): MutableLiveData<BaseResult<UpdateAppBean>> {
        launchGo({
            mGetUpgradeValue.value =
                loginRepository.getUpgrade(url,appInfo)
        }, true)
        return mGetUpgradeValue
    }

}